package com.tanhua.server.service;

import com.tanhua.domain.db.UserFreeze;
import com.tanhua.domain.mongo.Comment;
import com.tanhua.domain.mongo.Publish;
import com.tanhua.dubbo.api.db.UserFreezeApi;
import com.tanhua.dubbo.api.mongo.CommentApi;
import com.tanhua.dubbo.api.mongo.PublishApi;
import com.tanhua.server.interceptors.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.log4j.Logger;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class MovementsMqService {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Reference
    private CommentApi commentApi;

//    @Slf4j  --->   Logger log = Logger.getLogger(MovementsMqService.class);

    @Reference
    private PublishApi publishApi;
    @Reference
    private UserFreezeApi userFreezeApi;

    public void sendMsg(String publishId, int type) {
// debug  info  warn error 日志的输出级别
//        log.error("");
        Publish publish = publishApi.findById(publishId);

//        Publish
//        userId publish中那个pid type
        Map msgMap = new HashMap();
        msgMap.put("userId", UserHolder.getUserId());
        msgMap.put("pid", publish.getPid());
        msgMap.put("type", type);
        //判断该用户是否冻结发评论
        Long userId = publish.getUserId();
      UserFreeze userFreeze= userFreezeApi.findById(userId);
        if(userFreeze!=null) {
            if(userFreeze.getFreezingRange()==2){
                return;
            }
        }

        rocketMQTemplate.convertAndSend("tanhua-quanzi-recommend",msgMap);

        log.debug("对publish的操作消息发送成功........");
        log.info("aaa");
        log.warn("bbb");
        log.error("ccc");
//        System.out.println("对publish的操作消息发送成功........");

    }
}
